import { xhrPostJson } from '@/services';
import { DynamicObjectAny } from '@/typings';
import { transformRejectParams } from '@/pages/invoice/util';

export enum ArcvBorrowConfig {
  CREATE = 'ArcvBrw_C',
  DETAIL = 'ArcvBrw_D',
  EDIT = 'ArcvBrw_U',
  BILL_CODE = 'ArcvBrnw',
  BILL_NAME = '案件借阅',
  CREATE_LINK = '/invoice/arcv-borrow-invoice/create',
  EDIT_LINK = '/invoice/arcv-borrow-invoice/edit',
  DETAIL_LINK = '/invoice/arcv-borrow-invoice/detail',
}

export const ArcvBorrowI18N = {
  zh_CN: ArcvBorrowConfig.BILL_NAME,
  en_US: ArcvBorrowConfig.BILL_CODE,
};

const baseUrl = '/arcv/arcvBrwr';

export const apiUrl = {
  detail: `${baseUrl}/detail`, // 详情
  save: `${baseUrl}/save`, // 保存
  submit: `${baseUrl}/submit`, // 提交
  update: `${baseUrl}/update`, // 编辑
  findArcvJson: `${baseUrl}/findArcvJson`
};

export interface ArcvBorrowSubmitParams extends DynamicObjectAny {}

export interface ArcvBorrowSaveParams extends DynamicObjectAny {}

export interface ArcvBorrowDetailParams extends DynamicObjectAny {}

export interface ArcvBorrowUpdateParams extends DynamicObjectAny {}

// 提交
export const arcvBorrowSubmit = (params: ArcvBorrowSubmitParams) => {
  return xhrPostJson(apiUrl.submit, transformRejectParams(params));
};

// 保存
export const arcvBorrowSave = (params: ArcvBorrowSaveParams) => {
  return xhrPostJson(apiUrl.save, transformRejectParams(params));
};

// 编辑更新
export const arcvBorrowUpdate = (params: ArcvBorrowUpdateParams) => {
  return xhrPostJson(apiUrl.update, transformRejectParams(params));
};

// 详情页
export const arcvBorrowDetail = (params: ArcvBorrowDetailParams) => {
  return xhrPostJson(apiUrl.detail, params);
};

// 案件详情JSON
export const findArcvJson = (params: DynamicObjectAny) => {
  return xhrPostJson(apiUrl.findArcvJson, params);
};
